<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="编号" prop="number">
        <el-input  v-model="form.numberNum" disabled style="width: 280px;"/>
      </el-form-item>
      <el-form-item label="费用类型" prop="costType">
        <el-select v-model="form.costType"
                   @change="costTypeChange"
                   :disabled="form.costType&&title!='添加备用金申请'"
                   placeholder="请选择费用类型" style="width: 280px">
          <el-option
            v-for="dict in dict.type.travel_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-select
          v-model="form.projectName"
          placeholder="请选择"
          clearable
          :disabled="form.projectName&&title!='添加备用金申请'"
          style="width: 280px"
        >
          <el-option
            v-for="item in projectNameList"
            :key="item.projectName"
            :label="item.projectName"
            :value="item.projectName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="费用金额" prop="feeAmount">

        <el-input
          v-model="form.feeAmount"
          placeholder="请输入"
          clearable
          style="width: 280px"
          :disabled="isdisabled"
          @input="form.feeAmount=form.feeAmount.replace(/^\D*([0-9]\d*\.?\d{0,6})?.*$/,'$1')"
        >
          <i slot="suffix" style="font-style:normal;">万元</i>
        </el-input>
      </el-form-item>
      <el-form-item label="费用凭证" prop="attachment">
        <image-upload v-model="form.attachment" :isDisabled="isdisabled" :limit="5"/>
      </el-form-item>
      <el-form-item label="申请事由" prop="applyCourse">
        <el-input :disabled='isdisabled' v-model="form.applyCourse" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input :disabled='isdisabled' v-model="form.remarks" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div
      v-show="parentTaskId===null&&confirmVisible"
      class="dialog-footer"
      style="text-align:center"
    >
      <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
      <el-button :loading="buttonLoading" size="small" type="primary" @click="submitForm">提交</el-button>
    </div>
    <div
      v-show="parentTaskId==null&&!confirmVisible"
      class="dialog-footer"
      style="text-align:right"
    >
      <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
    </div>
      <!-- 工作流开始 -->
      <verify ref="verifyRef" :taskId="taskId"
              @submitCallback="submitCallback" :componentName="componentName"
              :deptId="dept.deptId"
              :taskVariables="taskVariables" :sendMessage="sendMessage"></verify>
  </div>
</template>

<script>
import {getFinanceImprest, getProjectList} from "@/api/oa/financeImprest";
import verify from "@/components/Process/Verify";
import {parseTime} from "@/utils/ruoyi";
export default {
  name: "FinanceImprestForm",
  dicts: ['cost_type','act_status','travel_type'],
  components: {
      verify
  },
  props: {
      businessKey: String, // 业务唯一标识
      parentTaskId: String, // 父级任务id
      taskId: String, // 任务id
      confirmVisible:{
          type: Boolean,
          default: true
      }
  },
  data() {
    return {
      componentName: "备用金申请",
      title:"",
      isdisabled:true,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
        projectNameList:[],
      // 表单校验
      rules: {
        applyCourse: [
          { required: true, message: "申请事由不能为空", trigger: "blur" }
        ],
        remarks: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ],
        feeAmount: [
          { required: true, message: "费用金额不能为空", trigger: "blur" }
        ],
        attachment: [
          { required: true, message: "oss集合不能为空", trigger: "blur" }
        ]
      },
      taskVariables: undefined,
      //消息提醒
      sendMessage: {},
      processKey: 'oa_finance_imprest',
      dept:"",
    };
  },
  mounted() {
    if (this.$store.state.user.roles[0]=="common"||this.$store.state.user.roles[0]=="board"){
      this.dept=this.$store.state.user.dept?this.$store.state.user.dept:"";
    }
  },
  watch: {
      businessKey: {
          immediate: true, // 很重要！！！
          handler (newVal) {
              if(newVal) {
                  this.getById()
              }
          }
      }
  },
  methods: {
    costTypeChange(){
      this.form.projectName=undefined;
      this.getProjectList();
    },
    getProjectList() {
      getProjectList().then(res => {
        this.projectNameList = res.data;
      });
    },
    submitCallback(){
        this.$emit("closeForm")
    },
    async getById() {
      const {data} = await getFinanceImprest(this.businessKey)
      this.form = data;
      if (data.actBusinessStatus.createTime){
            this.form.numberNum=this.processKey + '@' + parseTime(data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
    },
    /** 提交按钮 */
    submitForm() {
        getFinanceImprest(this.businessKey).then(response => {
            this.taskVariables = {
                entity: response.data,
                userRole: this.$store.state.user.roles[0]
            };
            this.sendMessage = {
          title: "备用金申请审批提醒",
          messageContent: this.$store.state.user.nickName + "审批通过了备用金申请"
        };
        });
        this.$refs.verifyRef.visible = true
        this.$refs.verifyRef.reset()
    },
  }
};
</script>
<style scoped>
    /* 设置滚动条宽度和高度 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
        width: 8px; /* 横向滚动条 */
        height: 8px; /* 纵向滚动条 必写 */
    }
    /* 设置滚动条样式 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
        background-color: #dde;
        border-radius: 3px;
    }
    #selectForm >>> .el-form-item__label {
        font-size: 12px;
    }
    ::v-deep .bjsm .el-form-item__content{
        width: calc(100% - 130px) !important;
    }
</style>
